package com.lagou.service;

import com.lagou.dao.UserDao;
import com.lagou.domain.User;

import java.sql.SQLException;

/**
 * @author Administrator
 */
public class CheckLogin {
    private User user;

    public CheckLogin(User user) {
        this.user = user;
    }

    /**
     * 登录
     */
    public boolean login(){
        try {
            return new UserDao(user).checkPassword();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }

    /**
     * 判断是否可以注册
     * @return true 可以注册  false 不能注册
     */
    public boolean register(){
        boolean flag = false;
        try {
            UserDao userDao = new UserDao(user);
            flag =  userDao.userIsExists();
            if(!flag){
                userDao.insertUser();
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return !flag;
    }
}
